from game import *
import blockReader

if __name__ == '__main__':

    r = blockReader.FileBlockReader('file.txt')
    b = r.getNextBlockValue()
    g = Game(b)
    # print(g.getBest())
    # b = Block([
    #     [2,2,3,0],
    #     [3,0,2,0],
    #     [1,0,0,0],
    #     [0,0,1,0]])
    # g = Game(b)
    # print(g.getBest())
    # b = Block([
    #     [2,2,3,0],
    #     [3,0,2,0],
    #     [1,1,1,0],
    #     [0,0,0,0]])
    # g = Game(b)
    # print(g.getBest())
    g._block.print()
    while not g._block.isWin(11):
        if g._block.isDead():
            break;
        move = g.getBest()

        g._block.move(move['move'])
        move['move'] = tranDirection(move['move'])
        print(move)
        # 采取行动
        value = g._block._value;
        with open('file.txt', 'w') as fp:

        	for row in value:
        		fp.write('%d,%d,%d,%d\n' % (row[0], row[1], row[2], row[3]));
        input()
        # 读取新的块
        newBlock = r.getNextBlockValue()
        # 构建新的游戏对象
        g = Game(newBlock)
        g._block.print()
